/*
 * Package il.ac.biu.cs.grossmm.test.cpptest
 * File CppConsumer.java
 * 
 * This is a part of presence service framework API. 
 * See javadoc for more information.
 *  
 * Copyright (C) 2006 Grossmann Mark
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package il.ac.biu.cs.grossmm.tests.cpptest;

import static il.ac.biu.cs.grossmm.api.keys.KeyFactory.*;
import static il.ac.biu.cs.grossmm.api.keys.PatternFactory.*;
import static il.ac.biu.cs.grossmm.api.presence.BaseVocabulary.*;
import static il.ac.biu.cs.grossmm.api.presence.ResourceType.*;
import il.ac.biu.cs.grossmm.api.cpp.BaseCppConsumer;
import il.ac.biu.cs.grossmm.api.cpp.State;
import il.ac.biu.cs.grossmm.api.keys.Key;
import il.ac.biu.cs.grossmm.api.presence.Entity;
import il.ac.biu.cs.grossmm.api.presence.ResourceType;

import java.util.logging.Logger;

public class CppConsumer extends BaseCppConsumer<FooPresenceValue> {
	Logger logger = Logger.getLogger("CppConsumer");
	
	static int count = 0;
	long t=0;

	public CppConsumer()
	{
		super("TEST CPP Consumer", FooPresenceValue.class, pattern(
			String.class, mandatory(RESOURCE_TYPE, ResourceType.class)), null,
			true);
	}

	public void notify(Entity watcher, Key target, State state,
		String subscriptID, FooPresenceValue contents)
	{
		// logger.info("NOTIFICATION: " + subscriptID + " state="+ state+" contents=" + contents);
		count++;
		if( count % 100000 == 0) {
			// System.out.println(count);
			long t0 = System.currentTimeMillis();
			
			if( t>0 )
				System.out.println(t0-t);
			
			t=t0;
		}
	}

	@Override
	public void run()
	{
		started();
		 
		for( int i=0; i<5000; i++ ) {
			subscribe(null, key("Alice"+i, entry(RESOURCE_TYPE, PRESENCE)),
				consumerName + 0, 100);
			
			if( i%10000 == 0 )
				System.out.println("subs "+i);
				
		}
	}
}
